#include <signal.h>
#include <stdio.h>

void sigcb(int sig)//信号处理方法
{
    printf("Get %d signal success..\n",sig);
}

int main()
{
    //捕捉2号信号
    //signal(SIGINT,sigcb);
    struct sigaction newact = {sigcb};
    struct sigaction oldact;
    sigaction(SIGINT,&newact,&oldact);

    //给自己发生2号信号
    int cnt = 6;
    while(--cnt)
    {
        printf("%d秒后收到2号信号..\n",cnt);
        sleep(1);
    }
    raise(SIGINT);

    return 0;
}